﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using Model;
namespace DAL
{
  public   class NavtionDAL
    {
        /// <summary>
        /// 链接字符串
        /// </summary>
        SqlConnection con = new SqlConnection(" Data Source=PC201609040948;Initial Catalog=TianTianDai_Db;Persist Security Info=True;User ID=sa;Pwd=123456");
        /// <summary>
        /// 大导航的显示功能
        /// </summary>
        /// <returns></returns>
        public List<Navigation>  Navigation_Show ()
        {
            con.Open();
            string sql = "select * from Navigation ";
            SqlDataAdapter adp = new SqlDataAdapter(sql, con);
            DataTable table = new DataTable();
            adp.Fill(table);
            con.Close();
            List<Navigation> list = new List<Navigation>();
            foreach (DataRow item in table.Rows)
            {
                Navigation navtion = new Navigation();
                navtion.NavigationId = Convert.ToInt32(item["NavigationId"]);
                navtion.NavigationName = item["NavigationName"].ToString();
                list.Add(navtion);
            }
            return list;
          
        }  
      /// <summary>
      /// 大导航的增加功能
      /// </summary>
      /// <param name="nav"></param>
      /// <returns></returns>
      public int  Navtion_Insert (Navigation nav)
        {
            con.Open();
            string sql = "insert into Navigation values ('" + nav.NavigationName + "')";
            SqlCommand com = new SqlCommand(sql, con);
            return com.ExecuteNonQuery();

        }
    }
}
